package com.zhy.system.handler;

import com.zhy.common.result.Result;
import com.zhy.system.exception.YuanException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 随缘而愈
 * @version 1.0
 * @description 全局异常处理
 * @date 11/3/2024 上午9:12
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result error(ArithmeticException e){
        e.printStackTrace();
        return Result.fail().message("执行了特定异常处理");
    }

    @ExceptionHandler(YuanException.class)
    @ResponseBody
    public Result error(YuanException e) {
        e.printStackTrace();
        return Result.fail().message(e.getMessage()).code(e.getCode());

    }

}
